//搜索框
(function(){
    $("#a").on("input",function(){
        $.ajax({
            url:"https://www.ymatou.com/products/api/getPreKeywordList",
            data:{
                // code:"utf-8",
                query:$(this).val(),
                // _:"1636373324903",
            },
            success:res=>{
                console.log(res.result.Keyword);
                let str = "";
                if(this.value === ""){
                    $(".lists").css("display","none")
                }
                res.result.Keywords.forEach(val=>{
                    str += `<li>${val}</li>`
                })
                $(".lists").css("display","block")
                $(".lists").html(str);
                // console.log($(".lists")[0]);
            },
            dataType:"jsonp",
            jsonp:"callback"
        })
    })
    $(document).on("click",function(){
        $(".lists").css("display","none")
    })
})()


//楼层
$(".lista").children("li").click(function(){
    $("html").animate({
        scrollTop: $(".lou").eq($(this).index()).offset().top
    })
    // const index = $(this).index();
    // const now = $(".lou").eq(index)
    // console.log(now.offset());
})
$(document).on("scroll", function(){
    if($(document).scrollTop() > 0){
        $(".lista").children("li").eq(0).css("background","lawngreen").siblings().css("background","")
    }
    if($(document).scrollTop() > 680){
        $(".lista").children("li").eq(1).css("background","lawngreen").siblings().css("background","")
    }
    if($(document).scrollTop() > 1670){
        $(".lista").children("li").eq(2).css("background","lawngreen").siblings().css("background","")
    }
    if($(document).scrollTop() > 2614){
        $(".lista").children("li").eq(3).css("background","lawngreen").siblings().css("background","")
    }
    if($(document).scrollTop() > 3063){
        $(".lista").children("li").eq(4).css("background","lawngreen").siblings().css("background","")
    }
    if($(document).scrollTop() >= 4200){
        $(".lista").children("li").eq(5).css("background","lawngreen").siblings().css("background","")
    }
})

//二级菜单
const erji = document.querySelector(".three-a-d-a");
const ejli = document.getElementById("ej");
    erji.style.display = "none";
    ejli.onmouseover = function(){
        erji.style.display = "block";
    }
    ejli.onmouseout = function(){
        erji.style.display = "none";
    }

// 用户信息
const ologin = document.querySelector("#ms");
    const owelcome = document.querySelector(".welcome");
    const un = owelcome.querySelector("span");
    const quit = owelcome.querySelector("em");

    const goCart = document.querySelector("#goCart");

    if(localStorage.getItem("isLogin") === "ok"){
        ologin.style.display = "none";
        owelcome.style.display = "block";
        un.innerHTML = localStorage.getItem("username")
    }else{
        ologin.style.display = "block";
        owelcome.style.display = "none";
    }

    quit.onclick = function(){
        localStorage.setItem("isLogin", "");
        localStorage.setItem("username", "");
        
        un.innerHTML = "";
        ologin.style.display = "block";
        owelcome.style.display = "none";
    }

    // goCart.onclick = function(){
    //     if(localStorage.getItem("isLogin") !== "ok"){
    //         return false;
    //     }
    // }



    